var $day = {
    settings: {
        selectDay: 'day',
        selectMonth: 'month',
        selectYear: 'year'
    },
    init:function(){
        $('#' + $day.settings.selectMonth).change(function(){
            $day.renderCombobox(
            $day.settings.selectDay,
            $day.getdays($(this).val(),
            $('#' + $day.settings.selectYear).val()),
            $('#' + $day.settings.selectDay).val()
        );
        });

        $('#' + $day.settings.selectYear).change(function(){
            $day.renderCombobox($day.settings.selectDay, $day.getdays(
            $('#' + $day.settings.selectMonth).val(),
            $(this).val()),
            $('#' + $day.settings.selectDay).val());
        });
    },
    getdays: function($month, $year){
        return ($month == 2) ?
            ($year != -1 ? $day.getDaysInMonth($month, $year) : 29) :
            $day.getDaysInMonth($month, 0);
    },
    getDaysInMonth: function($month, $year){
        return $month == 2 ? ($year % 4 ? 28 : ($year % 100 ? 29 : ($year % 400 ? 28 : 29))) : (($month - 1) % 7 % 2 ? 30 : 31);
    },
    //getOption: function($max, $selected = -1){
    getOption: function($max, $selected){
        $html = "<option value='-1'>Day:</option>";
        for($i = 1; $i <= $max; $i++){
            if($i != $selected){
                $html += "<option value='" + $i + "'>" + $i + "</option>";
            }
            else{
                $html += "<option selected='selected' value='" + $i + "'>" + $i + "</option>";
            }
        }
        return $html;
    },
    renderCombobox:function($id, $max, $selected){
        $('#' + $id).html($day.getOption($max, $selected));
    }
};